package cn.flying.cloud.base.common.vo;

import java.io.Serializable;

import cn.flying.cloud.base.common.enums.RtCodeEnum;

/**
 * 公共的返回对象
 *
 * @author: admin
 * @date: 2022年03月31日 20:47
 * @version: 1.0
 */
public class Rt<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 响应码
     */
    private String code;
    /**
     * 描述信息
     */
    private String msg;
    /**
     * 数据对象
     */
    private T data;

    public Rt() {
    }

    public Rt(String code, String msg) {
        this.code = code;
        this.msg = msg;
        this.data = null;
    }

    public Rt(String code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static <T> Rt<T> success() {
        return new Rt<T>(RtCodeEnum.R_SUCCESS.getCode(), RtCodeEnum.R_SUCCESS.getDesc());
    }

    public static <T> Rt<T> success(String message) {
        return new Rt<T>(RtCodeEnum.R_SUCCESS.getCode(), message);
    }

    public static <T> Rt<T> success(T data) {
        return new Rt<T>(RtCodeEnum.R_SUCCESS.getCode(), RtCodeEnum.R_SUCCESS.getDesc(), data);
    }

    public static <T> Rt<T> success(String message, T data) {
        return new Rt<T>(RtCodeEnum.R_SUCCESS.getCode(), message, data);
    }

    public static <T> Rt<T> error() {
        return new Rt<T>(RtCodeEnum.R_ERROR.getCode(), RtCodeEnum.R_ERROR.getDesc());
    }

    public static <T> Rt<T> error(RtCodeEnum codeEnum) {
        return new Rt<T>(codeEnum.getCode(), codeEnum.getDesc());
    }

    public static <T> Rt<T> error(String message) {
        return new Rt<T>(RtCodeEnum.R_ERROR.getCode(), message);
    }

    public static <T> Rt<T> error(String code, String message) {
        return new Rt<T>(code, message);
    }

    public static <T> Rt<T> result(String message) {
        return new Rt<T>(RtCodeEnum.R_SUCCESS.getCode(), message);
    }

    public static <T> Rt<T> result(RtCodeEnum codeEnum) {
        return new Rt<T>(codeEnum.getCode(), codeEnum.getDesc());
    }

    public static <T> Rt<T> result(RtCodeEnum codeEnum, T data) {
        return new Rt<T>(codeEnum.getCode(), codeEnum.getDesc(), data);
    }

}
